package org.uim.cricket.db.impl;

public class ExistPlayer extends DBBooleanResultQuery {

	private String pId = null;
	private String displayName = null;
	
	public ExistPlayer(String playerID, String theDisplayName) {
		pId = String.valueOf(playerID);
		this.displayName = theDisplayName;
	}
	
	public ExistPlayer(String thePlayerIDStr) {
		this.pId = thePlayerIDStr;
	}
	
	public boolean exists() {
		if (pId == null || pId.length() == 0) return false;
		
		try {
			
			if (this.displayName != null) {
				if (this.displayName.length() > 64) this.displayName = this.displayName.substring(0, 63);
				if (this.displayName.indexOf("'") >= 0) {
					this.displayName = this.displayName.replaceAll("'", "\\\\'");
				}
				
				return super.result("CALL sp_Exist_Player(" + pId + ",'"+  this.displayName +"');"); 
			} else {
				return super.result("CALL sp_Exist_Player(" + pId + ",NULL);"); 
			}
			
			
		} catch (Exception e) {
			e.printStackTrace();
		} 
		
		return false;
	}
	
	
}
